package gene.core.util;

import gene.core.Core;
import java.io.InputStream;
import java.io.Reader;
//import javax.microedition.lcdui.Graphics;
//import javax.microedition.lcdui.Image;

/*
 *
 * @author vlm
 *
public class Surface {

    public int  pallete       []  = null;
    public byte data          []  = null ;
    private short x_y_w_h_alpha   []  = {0,0,0,0,0};

    public Surface (byte _data[],int _pal[],int w,int h){
        data = _data;
        pallete = _pal;
        x_y_w_h_alpha[2] = (short)w;
        x_y_w_h_alpha[3] = (short)h;
        
    }

    public void setAlpha(int alpha){
     x_y_w_h_alpha[4] =(short) alpha;
    }


    private int arr2int (byte arr[],int start) {
		int low = arr[start] & 0xff;
		int high = arr[start+1] & 0xff;
		return (int)( high << 8 | low );
	}

    public int getH(){
        return x_y_w_h_alpha[3];
    }

    public int getW(){
        return x_y_w_h_alpha[2];
    }

    public int getX(){
        return x_y_w_h_alpha[0];
    }

    public int getY(){
        return x_y_w_h_alpha[1];
    }

    /*public void paint(){

      Graphics g = Core.getInstance().getCoreGraphics();
      int i = data.length;
      int alpha = 0; //calcalpha
      for(;--i>=0;){
        g.setColor(pallete[data[i]]);
        g.drawLine(x_y_w_h_alpha[0],x_y_w_h_alpha[1],1,1);
      }
    }*/

    /*pictures need have the same size
    public static void drawImageSum(Image _a,Image _b,int x, int y){
     int w = _a.getWidth();
     int h =_a.getHeight();
     int lngt = w * h;

     int a[] = new int[lngt];
     int b[] = new int[lngt];
     int r[] = new int[lngt];

     _a.getRGB( a , 0 , 0 , x, y, w , h );

     _b.getRGB( b , 0 , 0 , x, y, w , h );

     for(; --lngt > 0;){
         r[lngt] = a[lngt]<<8 | b[lngt]>>16;
        }

        Core.getInstance().getCoreGraphics().drawRGB(r, 0 , 0 , x , y , w , h , true);
    }*
    
    
  public void changeColor(int newColor, int color) {

      int i = data.length;
        //modifica a cor desejada
        for (; --i > 0;) {
                if ((pallete[i] ==  color) ) {
                     pallete[i] = newColor;
                }
         }

        
    }

    public static Image rotateImage(int angle) {
        return null;
    }
   
    public void changePalette(){
    }

    **
     * Changes size of bitmap.
     * @param sourceImage source image.
     * @param newWidth width of new image.
     * @param newHeight height of new image.
     * @return scaled image.
     **
    private Image scaleImage(Image sourceImage, int newWidth, int newHeight) {

        int oldWidth = sourceImage.getWidth();
        int oldHeight = sourceImage.getHeight();

        int[] inputData = new int[oldWidth * oldHeight];
        sourceImage.getRGB(inputData, 0, oldWidth, 0, 0, oldWidth, oldHeight);

        int[] outputData = new int[newWidth * newHeight];

        int YD = (oldHeight / newHeight - 1) * oldWidth;
        int YR = oldHeight % newHeight;
        int XD = oldWidth / newWidth;
        int XR = oldWidth % newWidth;
        int outOffset = 0;
        int inOffset = 0;

        for (int y = newHeight, YE = 0; --y > 0;) {
            for (int x = newWidth, XE = 0; --x > 0;) {
                outputData[outOffset++] = inputData[inOffset];
                inOffset += XD;
                XE += XR;
                if (XE >= newWidth) {
                    XE -= newWidth;
                    inOffset++;
                }
            }
            inOffset += YD;
            YE += YR;
            if (YE >= newHeight) {
                YE -= newHeight;
                inOffset += oldWidth;
            }
        }
        return Image.createRGBImage(outputData, newWidth, newHeight, false);
    }


    public void paint(){
        Graphics g = Core.graphics;
        int i = data.length-1;
        int _data [] = new int[i];
System.out.println("i "+i+" paleta "+pallete[0]);
        //for(; --i >= 0 ;){
            _data[0] = pallete[data[0]];
            g.setColor(pallete[10]);
            g.drawLine(0,0,20,20);
            //System.out.println(" data "+_data[i]);
        //}
        //Core.graphicDevice.bufferImage(_data);
    }

    public Surface loadBitmap(String filePal,String fileBMP){

    return null;
    }

    public static Image surfaceToImage(Surface surface){
        byte data[] = surface.data;
        int pal [] = surface.pallete;
        int image_data[] = new int[data.length];
        int i = data.length;

        for( ; --i >= 0 ; ){
         image_data[i] = pal[data[i]];

        }

        return Image.createRGBImage(pal,surface.getW(),surface.getH(),true);
    }
}*/
